package cn.lx.expansion;

import java.util.ArrayList;
import java.util.Random;

/**
 * @author lixin
 * @Classname Emperor
 * @Description TODO
 * @Date 2019/10/4 上午9:14
 */
public class Emperor {

    public static Integer maxNumOfEmperor = 3;

    public static ArrayList<String> nameList = new ArrayList<String>();

    public static ArrayList<Emperor> emperorArrayList = new ArrayList<Emperor>();

    public static Integer countNumOfEmperor;

    static {
        for (Integer i = 0; i < maxNumOfEmperor; i++) {
            emperorArrayList.add(new Emperor("hello" + (i + 1)));
        }
    }


    private Emperor() {
        // 空的构造方法
    }

    private Emperor(String name) {
        nameList.add(name);
    }

    public static Emperor getInstance() {
        // 通过该方法获取实例
        Random random = new Random();
        countNumOfEmperor = random.nextInt(maxNumOfEmperor);
        return emperorArrayList.get(countNumOfEmperor);
    }

    public static void say() {
        System.out.println(nameList.get(countNumOfEmperor));
    }
}
